<?php

/**
 * @author Huiyi
 */
class announcements extends CI_Controller{

   
    function __construct() {
        parent::__construct();
        $this->load->model('announcements_model');
    }

/*
|--------------------------------------------------------------------------
| getAnnouncements (@author : Huiyi)
|--------------------------------------------------------------------------
|
| This function returns the parsed announcements as JSON and call the 
| function to wrap the response in the requested callback. 
|
*/ 	
	public function getAnnouncements(){        
        $xmlAnnouncementsUrl = $this->config->item('announcements');

        // $output = '{"AnnouncementsInfo":{"date":"20 august 2013","announcements":"asdfghjk"}}';
		
		
        $output = $this->announcements_model->parseAnnouncementsXml($xmlAnnouncementsUrl, 0);
        $this->retJsonP($output);
    }
	
	
/*
|--------------------------------------------------------------------------
| retJsonP (@author : Huiyi)
|--------------------------------------------------------------------------
|
| This function wraps the response in the requested callback. 
|
*/
	    function retJsonP($output) {
        $callback = $_REQUEST['callback'];

        if ($callback) {
            header('Content-Type: text/javascript');
            echo $callback . '(' . json_encode($output) . ');';
        } else {
            header('Content-Type: application/x-json');
            echo json_encode($output);
        }
    }
}

?>





